﻿using System;
using System.Collections;
using System.Collections.Generic;
public class MyObject
{
    public MyObject(string fName, string lName)
    {
        this.Foo = fName;
        this.Bar = lName;
    }
    public string Foo;
    public string Bar;
}
class MyObjects : IEnumerable<MyObject>
{
    PeopleList<MyObject> mylist = new PeopleList<MyObject>();

    public MyObject this[int index]
    {
        get { return mylist[index]; }
        set { mylist.Insert(index, value); }
    }

    public IEnumerator<MyObject> GetEnumerator()
    {
        return mylist;
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}
public class PeopleList<T> : IEnumerator<T>, IEnumerator
{
    public T[] _people = new T[2];
    int position = -1;
    public PeopleList()
    {
        //_people = (Person[])val;

    }
    public T this[int index]
    {
        get { return _people[index]; }
        set { _people[index] = value; }
    }
    public void Insert(int index, T obj)
    {
        _people[index] = obj;
    }
    //public PeopleList(Person val)
    //{
    //}
    //public PeopleList(Person[] list)
    //{
    //    _people = list;
    //}
    public bool MoveNext()
    {
        position++;
        return (position < _people.Length);
    }
    public void Reset()
    {
        position = -1;
    }
    

    T IEnumerator<T>.Current
    {
        get { return _people[position]; }
    }

    public void Dispose()
    {
    }

    object IEnumerator.Current
    {
        get { return _people[position]; }
    }
}
class App
{
    static void Main()
    {
        MyObjects myObjects = new MyObjects();
        myObjects[0] = new MyObject("Hello", "1" );
        myObjects[1] = new MyObject("World", "2" );

        foreach (MyObject p in myObjects)
            Console.WriteLine(p.Foo + " " + p.Bar);
        Console.ReadLine();
    }
}